
package com.epam.android.training.level1.receiver;

import com.epam.android.training.level1.R;
import com.epam.android.training.level1.activity.IntentActions;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

/**
 * @author Anton Novikau
 */
public class PollUpdatesReceiver extends BroadcastReceiver implements IntentActions {

  @Override
  public void onReceive(Context context, Intent intent) {
    NotificationManager notificationManager = (NotificationManager) context
        .getSystemService(Context.NOTIFICATION_SERVICE);
    CharSequence ticker = context.getText(R.string.poll_update_notification_ticker);
    Notification notification = new Notification(android.R.drawable.stat_notify_sync, ticker,
        System.currentTimeMillis());
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    PendingIntent contentIntent = PendingIntent
        .getActivity(context, 0, new Intent(ACTION_TESTS), 0);
    notification.contentIntent = contentIntent;

    notification.setLatestEventInfo(context, ticker,
        context.getText(R.string.poll_update_notification_message), contentIntent);
    notificationManager.notify(R.id.poll_sync_notification, notification);
  }
}
